package com.hqyj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.dao.JobMapper;
import com.hqyj.pojo.Job;
import com.hqyj.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class JobServiceImpl implements JobService {
    @Autowired
    JobMapper jobMapper;

    public HashMap<String, Object> selectAllJob() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        try {
            //分页
            //1 设置分页页码，每页显示条数
//            PageHelper.startPage(0,2);
            //2查询
            List<Job> jobs = jobMapper.selectJob();

            //3获取分页对象
            PageInfo<Job> jobPageInfo = new PageInfo<Job>();

            if (jobs != null || jobs.size() > 1) {
                //获取当前页的集合
                map.put("info", jobs);
//                //总条数
//                long total = jobPageInfo.getTotal();
//                //总页数
//                int pages = jobPageInfo.getPages();
//
//                System.out.println("上一页="+jobPageInfo.getPrePage());
//                System.out.println("下一页="+jobPageInfo.getNextPage());
//                map.put("total",total);
//                map.put("pages",pages);
            } else {
                map.put("info", "当前没有职位信息！");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    public HashMap<String, Object> deleteBysId(int id) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        int i = jobMapper.deleteByPrimaryKey(id);
        if (i > 0) {
            map.put("info", "删除成功！");
        } else {
            map.put("info", "删除失败！");
        }
        return map;
    }

    public HashMap<String, Object> addJob(Job job) {

        HashMap<String, Object> map = new HashMap<String, Object>();

        int i = jobMapper.insertSelective(job);
        if (i > 0) {
            map.put("info", "添加成功！");
        } else {
            map.put("info", "添加失败！");
        }
        return map;
    }

}
